#include "smart-device-protocol.h"
#include <stdio.h>
#include <iostream>
#include <stdint.h>

int main(int argc, char const *argv[])
{
    SmartDeviceProtocol doorlockProtocol = SmartDeviceProtocol::makeDoorLockProtocol(0x01,
                                                                                     0x00,
                                                                                     0x00);
    doorlockProtocol.showPacket();
    cout << "-------------------------" << endl;

    vector<uint8_t> packet(doorlockProtocol.packetData(), doorlockProtocol.packetData() + doorlockProtocol.packetLen());
    SmartDeviceProtocol ackProtocol = SmartDeviceProtocol::makeProtocolFormPacket(packet);
    ackProtocol.showPacket();

#if 0
    // 4个16进制显示 [0] 成员高字节 [1] 低字节
    printf("packet head : %04x\n", ackProtocol.getPacketHead());
    printf("packet addr : %08x\n", ackProtocol.getPacketAddr());
    printf("packet id   : %02x\n", ackProtocol.getPacketID());
    printf("packet len  : %04x\n", ackProtocol.getPacketDataLen());
    printf("packet data : ");
    uint16_t datalen = ackProtocol.getPacketDataLen();
    uint8_t *data = ackProtocol.getPacketData();
    for (int i = 0; i < datalen; i++)
    {
        printf("%02x ", data[i]);
    }
    printf("\n");
    printf("packet sum: %04x\n", ackProtocol.getPacketCRC16());
#endif

    return 0;
}
